package com.hmall.search.web;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hmall.common.client.ItemClient;
import com.hmall.common.dto.Item;
import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;
import org.checkerframework.checker.units.qual.A;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    SearchService searchService;
    @Autowired
    ItemClient itemClient;
    @Autowired
    private RestHighLevelClient client;

    @GetMapping("/put")
    public void  put() throws InterruptedException {
        searchService.put();
    }
    @PostMapping("/list")
    public PageDTO<ItemDoc> search(@RequestBody RequestParams requestParams) {
        PageDTO<ItemDoc> search = searchService.search(requestParams);
        return search;
    }

    @GetMapping("/suggestion")
    public List<String> suggestion(String key){
        List<String> suggestion=searchService.suggestion(key);
        return suggestion;
    }

    @PostMapping("/filters")
    public Map<String, List<String>> filter(@RequestBody RequestParams params){
        return searchService.filters(params);
    }

}
